﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Drawing;
using System.Text;
using System.Threading.Tasks;
using Homework.Properties;

namespace Homework
{
    /// <summary>
    /// 背景类
    /// </summary>
    class BackGround
    {
        //获得游戏对象的矩形
        public Rectangle rectangle
        {
            get;
            set;
        }       

        public BackGround (Rectangle rec)
        {
            //对矩形赋值
            rectangle = rec;
            //给背景初速度赋值
            SpeedY = 5;
        }

        //定义背景速度
        private int SpeedY;

        /// <summary>
        /// 绘图函数
        /// </summary>
        /// <param name="graphics"></param>
        public void Draw(Graphics graphics)
        {
            graphics.DrawImage(Properties.Resources.BackGround,rectangle);
        }

        /// <summary>
        /// 处理移动
        /// </summary>
        public void Move()
        {
            //让背景图移动
            this.rectangle = new Rectangle(this.rectangle.X, this.rectangle.Y + SpeedY, rectangle.Width, rectangle.Height);
            //移动完成后 回到初始位置 形成滚轴          
            if (this.rectangle.Y>= 0)
            {
                this.rectangle = new Rectangle(this.rectangle.X,-631, rectangle.Width, rectangle.Height);
            }
        }
        
    }
}
